package von.seiji.cn.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.filters.Watermark;
import net.coobird.thumbnailator.util.ThumbnailatorUtils;
import org.junit.Test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.HighGui;
import org.opencv.objdetect.CascadeClassifier;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URL;
import java.util.*;
import java.util.List;

public class T10 {
    //引入训练好的人脸识别XML文件
    static String PAHT = "E:/GOF/OpenCV/bin/test/haarcascade_frontalface_alt.xml";
    static String IMAGE_PATH = "C:\\Users\\Administrator\\Desktop\\临时储物库\\图片2\\图片2\\suspect\\xianyif2-1.jpg";
    static String productPath = "E:/GOF/OpenCV";

    public static void main(String[] args) {

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	/*	String Path = Test.class.getResource("haarcascade_frontalface_alt.xml").getPath();
		System.out.println(Path);*/
        CascadeClassifier faceDetector = new CascadeClassifier();
        Mat image = Imgcodecs.imread(IMAGE_PATH);
        MatOfRect faceDetections = new MatOfRect();
        faceDetector.detectMultiScale(image, faceDetections);

        System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
        for (Rect rect : faceDetections.toArray()) {
            Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                    new Scalar(0, 255, 0));
        }

        String filename = "ouput.png";
        System.out.println(String.format("Writing %s", filename));
        boolean flag = Imgcodecs.imwrite(filename, image);
    }

    @Test
    public void test40() {
        //System.load("E:\\Seiji926\\software\\OpenVC\\opencv430\\build\\java\\x64\\opencv_java430.dll");
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        File file = new File(IMAGE_PATH);
        System.out.println(file.exists());
        Mat imread = Imgcodecs.imread(IMAGE_PATH);
        Image image = HighGui.toBufferedImage(imread);

        System.out.println(imread);
        Rect rect = new Rect(10, 10, 200, 200);
        Imgproc.rectangle(imread, rect.tl(), rect.br(), new Scalar(0, 255, 255));
        boolean imwrite = Imgcodecs.imwrite("F://1.jpg", imread);
        System.out.println(imwrite);

    }

    @Test
    public void test67() throws IOException {
        Thumbnails.of("").scale(0.2).watermark((Watermark) null)
                .outputQuality(1).toFile("");
        //Thumbnails.of(new URL("")).scale(0.1).to
    }

    @Test
    public void test81() {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat image = Imgcodecs.imread(IMAGE_PATH);
        //System.out.println("image = " + image);
        System.out.println(JSON.toJSONString(image));
    }

    @Test
    public void test90() {
        String data = "[-0.13299289345741272, 0.12711358070373535, 0.021426092833280563, 0.05710747838020325, -0.02865077182650566, -0.04708845540881157, 0.03749106079339981, -0.12876872718334198, 0.06926918774843216, -0.047905273735523224, 0.2887939512729645, -0.06768785417079926, -0.14072874188423157, -0.1723855435848236, 0.020202185958623886, 0.16752402484416962, -0.21153031289577484, -0.07565513253211975, -0.06157129257917404, 0.025771722197532654, 0.07134325802326202, -0.021475549787282944, 0.01687098667025566, 0.019116543233394623, 0.009416893124580383, -0.368195116519928, -0.04860491305589676, -0.1449514478445053, 0.0860518366098404, -0.037198737263679504, -0.029527343809604645, -0.019991781562566757, -0.17178185284137726, -0.10729867219924927, 0.03354806825518608, -0.011091739870607853, -0.056712906807661057, -0.003155539743602276, 0.22853761911392212, -0.06494135409593582, -0.1809193193912506, 0.02041557803750038, 0.07708852738142014, 0.25681790709495544, 0.22915129363536835, 0.08273684233427048, 0.028030212968587875, -0.14980261027812958, 0.1387561410665512, -0.13994859158992767, 0.009571344591677189, 0.10611604154109955, 0.16421477496623993, 0.06939172744750977, 0.02984454482793808, -0.13888655602931976, 0.01998639479279518, 0.021101465448737144, -0.15523983538150787, 0.009036731906235218, 0.08311577886343002, -0.02199711836874485, 0.03362926095724106, -0.025691907852888107, 0.27917128801345825, -0.02620680071413517, -0.11241472512483597, -0.13080304861068726, 0.09763891994953156, -0.133369579911232, -0.03937525674700737, 0.060211047530174255, -0.1353175789117813, -0.20514068007469177, -0.31634464859962463, 0.04583141580224037, 0.39565035700798035, 0.10742591321468353, -0.1555519849061966, 0.02817365899682045, -0.09167392551898956, -0.0471097007393837, 0.14171534776687622, 0.17374390363693237, -0.022928299382328987, -0.03521881252527237, -0.06919500976800919, -0.019505221396684647, 0.15344589948654175, -0.07066543400287628, -0.03789198026061058, 0.1755400151014328, -0.03909613937139511, 0.04011554270982742, -0.030880199745297432, -0.01308099552989006, -0.05932562053203583, 0.08778927475214005, -0.06942600756883621, -0.020763348788022995, 0.003379720263183117, -0.029357563704252243, 0.07684661448001862, 0.1258029192686081, -0.17939919233322144, 0.09520138800144196, -0.040813323110342026, 0.09798704832792282, 0.03274520859122276, -0.02615230903029442, -0.06081262230873108, -0.025540785863995552, 0.0596899576485157, -0.23427771031856537, 0.2307296097278595, 0.15455660223960876, 0.013800370506942272, 0.10508789867162704, 0.0756637379527092, 0.0759258046746254, -0.006775363348424435, 0.02385469153523445, -0.23359116911888123, 0.022396158427000046, 0.08600243926048279, 0.0010054814629256725, 0.09864114969968796, -0.008978882804512978]";
        List parse = (List) JSON.parse(data);
        System.out.println(parse.size());
        parse.forEach(System.out::println);
    }

    @Test
    public void test103() {
        String data = "[1.0, 3.0, 4.0, 3.0, 1.0, 4.0, 1.0, 5.0, 3.0, -0.047905273735523224, 0.2887939512729645, -0.06768785417079926, -0.14072874188423157, -0.1723855435848236, 0.020202185958623886, 0.16752402484416962, -0.21153031289577484, -0.07565513253211975, -0.06157129257917404, 0.025771722197532654, 0.07134325802326202, -0.021475549787282944, 0.01687098667025566, 0.019116543233394623, 0.009416893124580383, -0.368195116519928, -0.04860491305589676, -0.1449514478445053, 0.0860518366098404, -0.037198737263679504, -0.029527343809604645, -0.019991781562566757, -0.17178185284137726, -0.10729867219924927, 0.03354806825518608, -0.011091739870607853, -0.056712906807661057, -0.003155539743602276, 0.22853761911392212, -0.06494135409593582, -0.1809193193912506, 0.02041557803750038, 0.07708852738142014, 0.25681790709495544, 0.22915129363536835, 0.08273684233427048, 0.028030212968587875, -0.14980261027812958, 0.1387561410665512, -0.13994859158992767, 0.009571344591677189, 0.10611604154109955, 0.16421477496623993, 0.06939172744750977, 0.02984454482793808, -0.13888655602931976, 0.01998639479279518, 0.021101465448737144, -0.15523983538150787, 0.009036731906235218, 0.08311577886343002, -0.02199711836874485, 0.03362926095724106, -0.025691907852888107, 0.27917128801345825, -0.02620680071413517, -0.11241472512483597, -0.13080304861068726, 0.09763891994953156, -0.133369579911232, -0.03937525674700737, 0.060211047530174255, -0.1353175789117813, -0.20514068007469177, -0.31634464859962463, 0.04583141580224037, 0.39565035700798035, 0.10742591321468353, -0.1555519849061966, 0.02817365899682045, -0.09167392551898956, -0.0471097007393837, 0.14171534776687622, 0.17374390363693237, -0.022928299382328987, -0.03521881252527237, -0.06919500976800919, -0.019505221396684647, 0.15344589948654175, -0.07066543400287628, -0.03789198026061058, 0.1755400151014328, -0.03909613937139511, 0.04011554270982742, -0.030880199745297432, -0.01308099552989006, -0.05932562053203583, 0.08778927475214005, -0.06942600756883621, -0.020763348788022995, 0.003379720263183117, -0.029357563704252243, 0.07684661448001862, 0.1258029192686081, -0.17939919233322144, 0.09520138800144196, -0.040813323110342026, 0.09798704832792282, 0.03274520859122276, -0.02615230903029442, -0.06081262230873108, -0.025540785863995552, 0.0596899576485157, -0.23427771031856537, 0.2307296097278595, 0.15455660223960876, 0.013800370506942272, 0.10508789867162704, 0.0756637379527092, 0.0759258046746254, -0.006775363348424435, 0.02385469153523445, -0.23359116911888123, 0.022396158427000046, 0.08600243926048279, 0.0010054814629256725, 0.09864114969968796, -0.008978882804512978]";
        List<BigDecimal> strings = (List<BigDecimal>) JSONArray.parse(data);
        System.out.println(strings.size());
        BigDecimal max = Collections.max(strings);
        System.out.println(max);
        BigDecimal min = Collections.min(strings);
        System.out.println(min);
        Collections.sort(strings);
        System.out.println("strings = " + strings);
        Collections.sort(strings, new Comparator<BigDecimal>() {
            @Override
            public int compare(BigDecimal o1, BigDecimal o2) {
                return o2.compareTo(o1);
            }
        });
        System.out.println(strings);

        int i = Collections.binarySearch(strings, new BigDecimal(1.0));
        System.out.println(i);
        BigDecimal bigDecimal = strings.get(6);
        System.out.println("bigDecimal = " + bigDecimal);
        int frequency = Collections.frequency(strings, bigDecimal);
        System.out.println("是否包含？" + strings.contains(bigDecimal));
        System.out.println("frequency = " + frequency);
        Double a = -0.047905273735523224;
        System.out.println(a);
        System.out.println(new BigDecimal(1.0));
        System.out.println(new BigDecimal(0.1));

    }

    @Test
    public void test136() {
        String str = "helmet,helmet,helmet,helmet,helmet,helmet,helmet,helmet,helmet,suspect,suspect,suspect";
        String[] split = str.split(",");
        List<String> strings = Arrays.asList(split);
        int helmet = Collections.frequency(strings, "suspect");
        System.out.println(helmet);

    }


    @Test
    public void test147() {
        String data = "[1.0, 3.0, 4.0, 3.0, 1.0, 4.0, 1.0, 5.0, 3.0, -0.047905273735523224, 0.2887939512729645, -0.06768785417079926, -0.14072874188423157, -0.1723855435848236, 0.020202185958623886, 0.16752402484416962, -0.21153031289577484, -0.07565513253211975, -0.06157129257917404, 0.025771722197532654, 0.07134325802326202, -0.021475549787282944, 0.01687098667025566, 0.019116543233394623, 0.009416893124580383, -0.368195116519928, -0.04860491305589676, -0.1449514478445053, 0.0860518366098404, -0.037198737263679504, -0.029527343809604645, -0.019991781562566757, -0.17178185284137726, -0.10729867219924927, 0.03354806825518608, -0.011091739870607853, -0.056712906807661057, -0.003155539743602276, 0.22853761911392212, -0.06494135409593582, -0.1809193193912506, 0.02041557803750038, 0.07708852738142014, 0.25681790709495544, 0.22915129363536835, 0.08273684233427048, 0.028030212968587875, -0.14980261027812958, 0.1387561410665512, -0.13994859158992767, 0.009571344591677189, 0.10611604154109955, 0.16421477496623993, 0.06939172744750977, 0.02984454482793808, -0.13888655602931976, 0.01998639479279518, 0.021101465448737144, -0.15523983538150787, 0.009036731906235218, 0.08311577886343002, -0.02199711836874485, 0.03362926095724106, -0.025691907852888107, 0.27917128801345825, -0.02620680071413517, -0.11241472512483597, -0.13080304861068726, 0.09763891994953156, -0.133369579911232, -0.03937525674700737, 0.060211047530174255, -0.1353175789117813, -0.20514068007469177, -0.31634464859962463, 0.04583141580224037, 0.39565035700798035, 0.10742591321468353, -0.1555519849061966, 0.02817365899682045, -0.09167392551898956, -0.0471097007393837, 0.14171534776687622, 0.17374390363693237, -0.022928299382328987, -0.03521881252527237, -0.06919500976800919, -0.019505221396684647, 0.15344589948654175, -0.07066543400287628, -0.03789198026061058, 0.1755400151014328, -0.03909613937139511, 0.04011554270982742, -0.030880199745297432, -0.01308099552989006, -0.05932562053203583, 0.08778927475214005, -0.06942600756883621, -0.020763348788022995, 0.003379720263183117, -0.029357563704252243, 0.07684661448001862, 0.1258029192686081, -0.17939919233322144, 0.09520138800144196, -0.040813323110342026, 0.09798704832792282, 0.03274520859122276, -0.02615230903029442, -0.06081262230873108, -0.025540785863995552, 0.0596899576485157, -0.23427771031856537, 0.2307296097278595, 0.15455660223960876, 0.013800370506942272, 0.10508789867162704, 0.0756637379527092, 0.0759258046746254, -0.006775363348424435, 0.02385469153523445, -0.23359116911888123, 0.022396158427000046, 0.08600243926048279, 0.0010054814629256725, 0.09864114969968796, -0.008978882804512978]";
        List<Double> strings = JSONArray.parseArray(data, Double.class);
        System.out.println(strings);
        int frequency = Collections.frequency(strings, "1.0ewr");
        System.out.println(frequency);
    }


}